from typing import List


class Solution:
    def getDescentPeriods(self, prices: List[int]) -> int:
        n = len(prices)
        result = 0
        temp = 0

        for i in range(1, n):
            if prices[i - 1] - prices[i] == 1:
                result += 1
                temp += 1
            else:
                if temp > 1:
                    temp -= 1
                    while temp:
                        result += temp
                        temp -= 1
                temp = 0

        if temp > 1:
            temp -= 1
            while temp:
                result += temp
                temp -= 1

        result += n
        return result


if __name__ == '__main__':
    a = Solution()
    print(a.getDescentPeriods([12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 4, 3, 10, 9, 8, 7]))
